package movee.jpa.multi.source.controller;

import lombok.extern.slf4j.Slf4j;
import movee.jpa.multi.source.dao.primary.OperationSheetDao;
import movee.jpa.multi.source.dao.secondary.ClusterDao;
import movee.jpa.multi.source.repository.primary.OperationSheetRepo;
import movee.jpa.multi.source.repository.secondary.ClusterRepo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/v1", produces = "application/json")
@Slf4j
public class JpaMultiSourceController {

    private final ClusterRepo clusterRepo;
    private final OperationSheetRepo sheetRepo;

    public JpaMultiSourceController(ClusterRepo clusterRepo,
                                    OperationSheetRepo sheetRepo) {
        this.clusterRepo = clusterRepo;
        this.sheetRepo = sheetRepo;
    }

    @GetMapping(value = "/cluster/list", produces = "application/json")
    public List<ClusterDao> getTotalCluster() {
        log.info("getTotalCluster");
        List<ClusterDao> daos = clusterRepo.findAll();
        log.info("ClusterDao size: {}", daos.size());
        return daos;
    }

    @GetMapping(value = "/sheet/list", produces = "application/json")
    public List<OperationSheetDao> getTotalSheet() {
        log.info("getTotalCluster");
        List<OperationSheetDao> daos = sheetRepo.findAll();
        log.info("ClusterDao size: {}", daos.size());
        return daos;
    }
}
